﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Enter.Entity;
using Enter.Common;
using Enter.BizLogic;
using Enter.Config;
using Enter.Web.SystemAdmin;
namespace WebSystemAdmin.GoodClass
{
    public partial class GoodBrandEdit : PageBase
    {

        public int BID = RequestStrHelper.GetIntFromRequest("BID", 0);
        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!IsPostBack)
            {ListCtrlHelper.BindEnumOnListControl(ddl_Status, typeof(EnumStatus));
                if (BID != 0)
                {
                    GetInfo();
                }
            }
        }

        private void GetInfo()
        {
            T109_GoodBrandBLLSub bll = new T109_GoodBrandBLLSub();
            T109_GoodBrandEntity model = bll.GetObjectByBID(int.Parse(Request.QueryString["BID"]));
            if (model == null) return;
            txt_BID.Text = model.BID.ToString();
            txt_BName.Text = model.BName.ToString();
            
            txt_GoodClassID.Text = model.GoodClassID.ToString();
            txt_Weight.Text = model.Weight.ToString();
            txt_Descr.Text = model.Descr.ToString();
            this.ddl_Status.Items.FindByValue(((byte)model.Status).ToString()).Selected = true;
            txt_AddTime.Text = model.AddTime.ToString();
        }

        protected void btnApply_Click(object sender, EventArgs e)
        {
            T109_GoodBrandEntity model = new T109_GoodBrandEntity();
            T109_GoodBrandBLLSub bll = new T109_GoodBrandBLLSub();
            if (Request.QueryString["ID"] != null)
            {
                model.BID = BID;
            }
            model.BName = txt_BName.Text;
          
            //model.GoodClassID = int.Parse(txt_GoodClassID.Text);
            model.Weight = int.Parse(txt_Weight.Text);
            model.Descr = txt_Descr.Text;
            model.Status = (EnumStatus)byte.Parse(ddl_Status.SelectedValue);
            model.AddTime = DateTime.Parse(txt_AddTime.Text);
            if (bll.Save(model))
            {
                Utils.throwErrorGotoURL("添加成功", "GoodBrandList.aspx");
            }
            else
            {
                Utils.ShowMessage("添加失败");
            }
        }
    }
}
